<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:param name="eid"  select="pippo" />
    <xsl:param name="empty" />
    
    <xsl:template match="/">
        <xsl:apply-templates select="//expression[eidentifier=$eid]" mode="first-time" />
    </xsl:template>
    
    <xsl:template match="expression" mode="first-time">
        <message>
            <div class="work-info">
                <h3 class="work-title">Opera <b><xsl:value-of select="//metadati[1]/work/wtitle" /></b></h3>                
                <div id="father-div">
                    <xsl:variable name="fatherID"><xsl:value-of select="esource" /></xsl:variable>
                    <xsl:apply-templates select="//expression[eidentifier=$fatherID]" mode="father" />
                </div>
                <div id="sons-div">
                    <label for="sons-opt">Figliuoli</label>
                    <select id="sons-opt">
                        <optgroup label="Discussioni">
                            <xsl:apply-templates select="//expression[erelation=$eid][etype='dibattito']" mode="sons"/>
                        </optgroup>
                        <optgroup label="Risposte">
                            <xsl:apply-templates select="//expression[erelation=$eid][etype='risposta']" mode="sons"/>
                        </optgroup>
                        <optgroup label="Riassunti">
                            <xsl:apply-templates select="//expression[erelation=$eid][etype='riassunto']" mode="sons"/>
                        </optgroup>
                        <optgroup label="Sintesi">
                                <xsl:apply-templates select="//expression[erelation=$eid][etype='sintesi']" mode="sons"/>
                        </optgroup>
                        <optgroup label="Revisioni">
                            <xsl:apply-templates select="//expression[erelation=$eid][etype='revisione']" mode="sons"/>
                        </optgroup>
                    </select>
                </div>
                <div id="capostipite-div">
                    <xsl:apply-templates select="//expression[erelation=$empty]" mode="roots"/>
                </div>
            </div>
        </message>
    </xsl:template>
    
    <xsl:template match="expression" mode="father">
        <p>Padre: <xsl:value-of select="etitle" /></p>
    </xsl:template>
    
    <xsl:template match="expression" mode="sons">
        <option onclick="UILoadScheda ('{eidentifier/text()}')"><xsl:value-of select="../etitle" /></option>
    </xsl:template>

    <xsl:template match="expression" mode="roots">
        <p>Capostipite: <a href="javascript:UILoadScheda('{eidentifier/text()}');"><xsl:value-of select="etitle" /></a></p>
    </xsl:template>
    
    <xsl:template match="expression" mode="father">
        <p>Papà: <a href="javascript:UILoadScheda('{eidentifier/text()}');"><xsl:value-of  select="etitle"/></a></p>
    </xsl:template>
    
</xsl:stylesheet>
